<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<!-- Set render engine for 360 browser -->
	<meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- HTML5 shim for IE8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <![endif]-->

	<link href="/edocs/statics/simpleboot/themes/<?php echo C('SP_ADMIN_STYLE');?>/theme.min.css" rel="stylesheet">
    <link href="/edocs/statics/simpleboot/css/simplebootadmin.css" rel="stylesheet">
    <link href="/edocs/statics/js/artDialog/skins/default.css" rel="stylesheet" />
    <link href="/edocs/statics/simpleboot/font-awesome/4.2.0/css/font-awesome.min.css"  rel="stylesheet" type="text/css">
    <style>
		.length_3{width: 180px;}
		form .input-order{margin-bottom: 0px;padding:3px;width:40px;}
		.table-actions{margin-top: 5px; margin-bottom: 5px;padding:0px;}
		.table-list{margin-bottom: 0px;}
	</style>
	<!--[if IE 7]>
	<link rel="stylesheet" href="/edocs/statics/simpleboot/font-awesome/4.2.0/css/font-awesome-ie7.min.css">
	<![endif]-->
<script type="text/javascript">
//全局变量
var GV = {
    DIMAUB: "/edocs/",
    JS_ROOT: "statics/js/",
    TOKEN: ""
};
</script>
<!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="/edocs/statics/js/jquery.js"></script>
    <script src="/edocs/statics/js/wind.js"></script>
    <script src="/edocs/statics/simpleboot/bootstrap/js/bootstrap.min.js"></script>
<?php if(APP_DEBUG): ?><style>
		#think_page_trace_open{
			z-index:9999;
		}
	</style><?php endif; ?>
</head>

<body class="J_scroll_fixed">
	<div class="wrap J_check_wrap">
		<form id="add_fl_form" method="post" class="J_ajaxForm" action="<?php echo U('AdminTerm/addflitem');?>">
			<div class="table-actions">
				<input type="text" class="input inputbox" id="ctext" placeholder="请输入分类名称">
				<button id="fename" class="btn btn-primary btn-small" type="button">添加分类</button>
			</div>
			<table class="table table-hover table-bordered table-list">
				<thead>
					<tr>

						<th width="50">序号</th>
						<th>分类名称</th>
						<th>分类项列表</th>

					</tr>
				</thead>
				<tbody id="tbody">

				</tbody>
			</table>
		</form>

		<div class="form-actions">
			<button class="btn btn-primary btn_submit" type="submit" onclick=submit()>提交</button>
			<a class="btn" href="<?php echo U('AdminTerm/index');?>">返回</a>
		</div>
	</div>
	<script type="text/javascript" src="/edocs/statics/js/common.js"></script>
	<script>
 
	$('#fename').on('click', function (e) {
	 e.preventDefault();
	  var btn = $(this),
          form = btn.parents('form.J_ajaxForm');
		 
          btn.parent().find('span').remove();
		  var ctext=form.find('input.inputbox').val();
           if (ctext!='') {
           		// alert(form.find('input.inputbox').val());
				  
				   $('<tr><td></td><td><input class="input" name="data[]" value='+ctext+' type="text"  /></button><button class="btn-main-del btn btn-warning btn-small" type="button">删除</button></td><td><div class="btn-con"><input class="input" name="clist[]" type="text"  placeholder="点击右边按钮添加项" /><button class="btn-fl-add btn btn-primary btn-small" type="button">添加</button><button class="btn-fl-del btn btn-warning btn-small" type="button">删除</button></div></td></tr>').appendTo(form.find('table tbody')).fadeIn('fast');
       
		  renum();
		  
		}else{
           	 $('<span class="tips_error">请输入分类名称</span>').appendTo(btn.parent()).fadeIn('fast');
           }

		});

/*添加分类项按钮*/
	$("#tbody").on("click",".btn-fl-add", function() {
		$('<div class="btn-con"><input class="input" name="data[]["a"]" type="text"  placeholder="点击右边按钮添加项" /><button class="btn-fl-add btn btn-primary btn-small" type="button">添加</button><button class="btn-fl-del btn btn-warning btn-small" type="button">删除</button></div><span class="tips_error"></span>').appendTo($(this).parent().parent()).fadeIn('fast');
	});
/*删除分类项按钮*/
$("#tbody").on("click",".btn-fl-del", function() {		
	if($(this).parent().parent().children('.btn-con').length>1){			
		$(this).parent().remove().fadeOut('fast');
	}else{			
	 	$('<span class="tips_error">分类项不能少于一项。</span>').appendTo($(this).parent()).fadeIn('fast');
					//  $(this).parent().text('<span class="tips_error">分类项不能少于一项。</span>').fadeIn('fast');									
		};		
});
/*删除分类项按钮*/
$("#tbody").on("click",".btn-main-del", function() {		
	$(this).parent().parent().remove().fadeOut('fast');
renum();
	

	
    })
/*表格出新生成序号*/
function renum(){
	var length = $("#tbody").find("tr").length;  //#tb为Table的id  获取所有行
            for (i = 0; i < length; i++) {
             $("#tbody tr").eq(i).children("td").eq(0).html(i+1);  //给每行的第一列重写赋值
            }
}
function submit(){
	// $("#add_fl_form").submit();
	var shuju=new Object();
	
var length = $("#tbody").find("tr").length; 
	 for (i = 0; i < length; i++) {
             shuju.namee[i]=$("#tbody tr").eq(i).children("td").eq(1).html();  //给每行的第一列重写赋值
			 shuju.qt[i]="sad";
        }
	console.log(shuju);
};
	</script>
</body>

</html>